<?php
/**
 * pdo_sqlite数据驱动
 *
 * @package if
 * @subpackage module.db.drivers.pdo
 * @since 1.0
 */
class IDbPdoSqlite extends IAbstractDbPdo {
	protected $pdoType = "sqlite";
	
	protected $startQuote = "\"";
	protected $endQuote = "\"";
	
	protected $metaTableSQL = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name";
	
	function nConnect() {
		parent::nConnect();
		$charset = $this->config("charset");
		if ($charset) {
			$this->exec("PRAGMA encoding=\"{$charset}\"");
		}
	}
	
	function dsn() {
		return "sqlite:" . $this->config("path");
	}
	
	function checkOptions() {
		return true;
	}
	
	/**
	 * Enter description here...
	 * 
	 * @param unknown_type $name
	 * @return array
	 */
	function describeTable($name) {
		$array = $this->fetchAll($this->nativeExec("PRAGMA table_info(\"" . $name . "\")"));
		$fields = array();
		foreach ($array as $row) {
			$type = explode("(", $row["type"]);
			$size = null;
			if (count($type) == 2) {
			    $size = trim($type[1], ")");
			}
			$column = $row["name"];
			$fields[$column] = array(	
				"name" => $column,
				"type" => $type[0],
				"max_length" => $size,
				"not_null"  => (bool)$row["notnull"],
				"primary_key" => ($row["pk"] == 1),
				"has_default" => !is_null($row["dflt_value"]),
				"default_value" => $row["dflt_value"]
			);
			$fields[$column]["data_type"] = $this->dataType($fields[$column]);
		}
		return $fields;
	}	
	
	
	function nLimit($sql, $count, $offset = 0) {
		return $sql . " LIMIT {$offset},{$count}";
	}
}


?>